package com.lesama.test;

import java.util.Random;
import java.util.Scanner;

public class ArrayTest2 {
    public static void main(String[] args) {
        int[] arr = initArrayFromRandom();
//        int[] arr = initArrayFromScanner();
        System.out.println("班级里面成绩最高为" + getMaxNum(arr));
    }
    public static int[] initArrayFromRandom() {
        Random r = new Random();
        int[] arr = new int[5];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(100) + 1;
            System.out.println(arr[i]);
        }
        return arr;
    }
    public static int[] initArrayFromScanner() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入班级人数：");
        int count = sc.nextInt();
        int[] arr = new int[count];

        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个成绩：");
            arr[i] = sc.nextInt();
        }
        return arr;
    }
    public static int getMaxNum(int[] arr) {
        int n = arr.length;
        if(n == 0) {
            return 0;
        }
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            max = Math.max(max, arr[i]);
        }
        return max;
    }
}
